257B - Playing Cubes - CodeForces Solution


games greedy implementation *1300

Please click on ads to support us..

Python Code:

n,m=list(map(int,input().split()))
result=[[],[]]
a=n
b=m
count=0
while count<n+m:
    if count%2==0:
        if result[0]==[]:
            result[0].append(1)
            a-=1
        else:
            if result[0][count-1]==1 and a>0:
                result[0].append(1)
                a-=1
            elif result[0][count-1]==-1 and b>0:
                result[0].append(-1)
                b-=1
            else:
                if a>0:
                    result[0].append(1)
                    a-=1
                else:
                    result[0].append(-1)
                    b-=1
    else:
        if result[0][count-1]==1 and b>0:
            result[0].append(-1)
            b-=1
        elif result[0][count-1]==-1 and a>0:
            result[0].append(1)
            a-=1
        else:
            if a>0:
                result[0].append(1)
                a-=1
            else:
                result[0].append(-1)
                b-=1
    count+=1
a=n
b=m
count=0
while count<n+m:
    if count%2==0:
        if result[1]==[]:
            result[1].append(-1)
            b-=1
        else:
            if result[1][count-1]==1 and a>0:
                result[1].append(1)
                a-=1
            elif result[1][count-1]==-1 and b>0:
                result[1].append(-1)
                b-=1
            else:
                if a>0:
                    result[1].append(1)
                    a-=1
                else:
                    result[1].append(-1)
                    b-=1
    else:
        if result[1][count-1]==1 and b>0:
            result[1].append(-1)
            b-=1
        elif result[1][count-1]==-1 and a>0:
            result[1].append(1)
            a-=1
        else:
            if a>0:
                result[1].append(1)
                a-=1
            else:
                result[1].append(-1)
                b-=1
    count+=1
score=[[],[]]
for i in range(len(result)):
    p=0
    v=0
    for j in range(len(result[i])-1):
        if result[i][j]==result[i][j+1]:
            p+=1
        else:
            v+=1
    score[i].append(p)
    score[i].append(v)
index=0
if score[1][0]>score[0][0]:
    index=1
for i in score[index]:
    print(i,end=" ")
	  	   		 			   	 		  	 	 	  		

C++ Code:

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0);
    ll n,m;
    cin>>n>>m;
    cout<<n+m-1-min(n,m)<<" "<<min(n,m);
    return 0;
}


Comments

Submit
0 Comments
More Questions

1335A - Candies and Two Sisters
96B - Lucky Numbers (easy)
1151B - Dima and a Bad XOR
1435B - A New Technique
1633A - Div 7
268A - Games
1062B - Math
1294C - Product of Three Numbers
749A - Bachgold Problem
1486B - Eastern Exhibition
1363A - Odd Selection
131B - Opposites Attract
490C - Hacking Cypher
158B - Taxi
41C - Email address
1373D - Maximum Sum on Even Positions
1574C - Slay the Dragon
621A - Wet Shark and Odd and Even
1395A - Boboniu Likes to Color Balls
1637C - Andrew and Stones
1334B - Middle Class
260C - Balls and Boxes
1554A - Cherry
11B - Jumping Jack
716A - Crazy Computer
644A - Parliament of Berland
1657C - Bracket Sequence Deletion
1657B - XY Sequence
1009A - Game Shopping
1657A - Integer Moves